package com.gxa.worker.recycling.service.impl;

import com.gxa.core.recycling.common.ExceptionCode;
import com.gxa.core.recycling.exception.BusinessException;
import com.gxa.core.recycling.pojo.Recycler;
import com.gxa.worker.recycling.mapper.RecycleorderMapper;
import com.gxa.worker.recycling.mapper.RecyclerMapper;
import com.gxa.worker.recycling.service.RecyclerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
import java.util.Map;

/**
 * @author Bei
 * @date 2021/12/2 18:52
 */
@Service
public class RecycleServiceImpl implements RecyclerService {


    @Autowired
    RecyclerMapper recyclerMapper;




    @Override
    public void updateWorkerPwd(Long id,String firstPwd,String phone,String oldPwd, String newPwd) throws BusinessException {
//        Recycler recycler = new Recycler();
//        recycler.setPhone(phone);
        Recycler recycler1 = recyclerMapper.selectByPrimaryKey(id);
        if (!recycler1.getPhone().equals(phone) || !recycler1.getPwd().equals(firstPwd)){
            throw new BusinessException(ExceptionCode.PHONE_PWD_WRONG);
        }
        if (!oldPwd.equals(newPwd)){
            throw new BusinessException(ExceptionCode.DOUBLEPWD_WRONG);
        }
        recycler1.setPwd(newPwd);
        Example example = new Example(Recycler.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("phone",phone);
        recyclerMapper.updateByExampleSelective(recycler1,example);
    }

    @Override
    public Recycler pwdAndPhone(Long id) {
        Recycler recycler = recyclerMapper.selectByPrimaryKey(id);
        return recycler;
    }
}
